<template>
  <div class="a">
    <div class="header-back" :style="opacityObjOfBack">
      <span class="back iconfont">&#xe624;</span>
    </div>
    <div class="header-top" :style="opacityObj">
      <span @click="$router.push('/')" class="header-top-back iconfont">&#xe624;</span>
      景点详情
    </div>
  </div>
</template>
<script>
export default {
  name: "detailHeaderTop",
  data() {
    return {
      opacityObjOfBack: {
        opacity: 1
      },
      opacityObj: {
        opacity: 0
      },
      scrollTop: 0
    };
  },
  activated() {//进入页面后触发---使用keepalia标签后
    window.addEventListener("scroll", this.handleScroll);
  },
  deactivated(){//页面隐藏时(跳转)
    window.removeEventListener('scroll',this.handleScroll)
  },
  methods:{
    handleScroll(){
      // console.log("scroll")
      const top = document.documentElement.scrollTop
      let op = 0
      if(top > 40){
        op = top / 140
        op = op > 1 ? 1 : op
        this.opacityObj.opacity = op
        this.opacityObjOfBack = 0
      }else{
        this.opacityObj.opacity = 0
        this.opacityObjOfBack = 1 - op
      }
    }
  }
};
</script>
<style lang="less" scoped>
@import "~styles/varibles.less";
.a {

  .header-back {
    position: absolute;
    left: 0.2rem;
    top: 0.2rem;
    width: 0.6rem;
    height: 0.6rem;
    line-height: 0.6rem;
    text-align: center;
    background: rgba(0, 0, 0, 0.9);
    border-radius: 0.3rem;
    .back {
      color: #eee;
    }
  }
  .header-top {
    z-index: 2;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: @headerHeight;
    background-color: @bgColor;
    line-height: @headerHeight;
    color: #fff;
    text-align: center;
    .header-top-back {
      display: inline-block;
      width: 0.64rem;
      float: left;
    }
  }
}
</style>
